package d03_thread_callable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 *
 */
public class Test3Callable {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //需求：同房统计1~100之间的偶数和，统计1~100之间的奇数和

        //3.创建Callable自定义任务对象
        MyCallableOne c1 = new MyCallableOne();

        //4.创建FutureTask未来任务对象，封装Callable任务对象
        FutureTask<Integer> ft1 = new FutureTask<>(c1);

        //5.将任务交给Thread处理
        Thread thread = new Thread(ft1);
        thread.start();

        int sum = 1;
        for (int i = 3; i <= 100; i+=2) {
            sum += i;
            System.out.println("主线程：" + sum);
        }

        System.out.println("主线程，统计奇数和的结果：" + sum);


        //6.使用FutureTask获取Callable任务对象返回的结果
        Integer  result1 = ft1.get();
        System.out.println("线程1，统计偶数和的结果："+result1);


    }
}
